package com.gzx.plugin.tjzy.modular.call.pre.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzx.plugin.tjzy.modular.call.pre.bo.GzxPreOutCallAddBo;
import com.gzx.plugin.tjzy.modular.call.pre.bo.GzxPreOutCallDeleteBo;
import com.gzx.plugin.tjzy.modular.call.pre.bo.GzxPreOutCallQueryBo;
import com.gzx.plugin.tjzy.modular.call.pre.service.GzxPreOutCallService;
import com.gzx.plugin.tjzy.modular.call.pre.vo.GzxPreCallBusinessVo;
import com.gzx.plugin.tjzy.modular.call.pre.vo.GzxPreOutCallDetailVo;
import com.gzx.plugin.tjzy.modular.call.pre.vo.GzxPreOutCallVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.annotation.CommonNoRepeat;
import vip.xiaonuo.common.pojo.CommonResult;

import java.io.IOException;

/**
 * @author zjt
 * @description
 * @date 2024/11/8 16:20
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/tjzy/pre")
public class GzxPreOutCallController {

    private final GzxPreOutCallService preOutCallService;

    /**
     * 预测外呼数据坐席导入
     *
     * @param multipartFile excel
     */
    @CommonNoRepeat
    @CommonLog("预测外呼数据坐席导入")
    @PostMapping("/agentImportExcel")
    public CommonResult<String> agentImportExcel(@RequestPart("preOutCallAddBo") GzxPreOutCallAddBo preOutCallAddBo, @RequestPart("multipartFile") MultipartFile multipartFile) throws IOException {
        return CommonResult.data(preOutCallService.agentImportExcel(preOutCallAddBo, multipartFile));
    }

    /**
     * 预测外呼数据主管导入
     *
     * @param multipartFile excel
     */
    @CommonNoRepeat
    @CommonLog("预测外呼数据主管导入")
    @PostMapping("/adminImportExcel")
    public CommonResult<String> adminImportExcel(@RequestPart("preOutCallAddBo") GzxPreOutCallAddBo preOutCallAddBo, @RequestPart("multipartFile") MultipartFile multipartFile) throws IOException {
        return CommonResult.data(preOutCallService.adminImportExcel(preOutCallAddBo, multipartFile));
    }

    @PostMapping("/pageList")
    public CommonResult<Page<GzxPreOutCallVo>> pageList(@RequestBody GzxPreOutCallQueryBo preOutCallQueryBo) throws IllegalAccessException {
        return CommonResult.data(preOutCallService.pageList(preOutCallQueryBo));
    }

    @PostMapping("/pageDetail")
    public CommonResult<Page<GzxPreOutCallDetailVo>> pageDetail(@RequestBody GzxPreOutCallQueryBo preOutCallQueryBo) {
        return CommonResult.data(preOutCallService.pageDetail(preOutCallQueryBo));
    }

    @GetMapping("/getPreOutCallDetailById/{id}")
    public CommonResult<GzxPreOutCallDetailVo> getPreOutCallDetailById(@PathVariable Long id) {
        return CommonResult.data(preOutCallService.getPreOutCallDetailById(id));
    }

    @GetMapping("/getCallCount/{batchNumber}")
    public CommonResult<Integer> getCallCount(@PathVariable String batchNumber, @RequestParam("filterType") Integer filterType) {
        return CommonResult.data(preOutCallService.getCallCount(batchNumber, filterType));
    }

    @GetMapping("/startCallTask/{batchNumber}")
    @CommonLog("预测外呼任务开始")
    @CommonNoRepeat
    public CommonResult<String> startCallTask(@PathVariable String batchNumber) {
        return preOutCallService.startCallTask(batchNumber);
    }

    @GetMapping("/closeCallTask/{batchNumber}")
    @CommonLog("预测外呼任务关闭")
    @CommonNoRepeat
    public CommonResult<Void> closeCallTask(@PathVariable String batchNumber) {
        preOutCallService.closeCallTask(batchNumber);
        return CommonResult.ok();
    }

    @GetMapping("/continueCallTask/{batchNumber}")
    @CommonLog("预测外呼任务继续")
    @CommonNoRepeat
    public CommonResult<String> continueCallTask(@PathVariable String batchNumber) {
        return preOutCallService.continueCallTask(batchNumber);
    }

    @GetMapping("/finishCallTask/{batchNumber}")
    @CommonLog("预测外呼任务完结")
    @CommonNoRepeat
    public CommonResult<String> finishCallTask(@PathVariable String batchNumber) {
        preOutCallService.finishCallTask(batchNumber);
        return CommonResult.ok();
    }

    @GetMapping("/changeCallee/{batchNumber}")
    @CommonLog("预测外呼任务更换主叫")
    @CommonNoRepeat
    public CommonResult<String> changeCallee(@PathVariable String batchNumber, @RequestParam("caller") String caller) {
        preOutCallService.changeCallee(batchNumber, caller);
        return CommonResult.ok();
    }

    @GetMapping("/getPreCallBusinessById/{id}")
    public CommonResult<GzxPreCallBusinessVo> getPreCallBusinessById(@PathVariable Long id) {
        return CommonResult.data(preOutCallService.getPreCallBusinessById(id));
    }

    @GetMapping("/testCallParam/{batchNumber}")
    public CommonResult<Void> getCallParam(@PathVariable String batchNumber) {
        preOutCallService.testCallParam(batchNumber);
        return CommonResult.ok();
    }

    @PostMapping("/deletePreOutCall")
    @CommonLog("删除预测外呼")
    @CommonNoRepeat
    public CommonResult<String> deletePreOutCall(@RequestBody GzxPreOutCallDeleteBo bo) {
        return CommonResult.data(preOutCallService.deletePreOutCall(bo));
    }

    @PostMapping("/copyPreOutCallDetail")
    @CommonLog("更新预测外呼批次")
    @CommonNoRepeat
    public CommonResult<String> copyPreOutCallDetail(@RequestBody GzxPreOutCallAddBo preOutCallAddBo) {
        return CommonResult.data(preOutCallService.copyPreOutCallDetail(preOutCallAddBo));
    }

    @GetMapping("/closeErrorTask/{taskId}")
    @CommonLog("异常任务关闭")
    @CommonNoRepeat
    public CommonResult<String> closeErrorTask(@PathVariable String taskId) {
        preOutCallService.closeErrorTask(taskId);
        return CommonResult.ok();
    }
}
